<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>整数反转</title>
</head>
<body>

</body>
<script>
    const reverse = function (x) {
        let pow = Math.pow(2,31);
       if(x>pow-1||x<-pow){
           return 0
       }
        let isPlus = x>0;// 对否为整数
        let str = Math.abs(x).toString(); // 数字转化为字符串
        let arr = str.split('');// 字符串转换为数组
        let resArr = arr.reverse();// 数组反转
        let resStr = resArr.join('');
        let res =  isPlus ? Number(resStr) : -Number(resStr);
        if(res>pow-1||res<-pow){
            return 0
        }
        return  res;
    };
    // console.log(1 <<< 30);
    // console.log(1 >>> 30);
</script>
</html>
